import { provinceData } from './province';
import { cityData } from './city';
import { areaData } from './area';

export interface childrenData {
  label?: string;
  value?: string;
  id: string
  text: string
  longitude: string;
  latitude: string;
  pid: number;
  children: Array<childrenData>
}

export function getCity_areaData(cityLevel?: 'province' | 'city' | 'area'): childrenData[] {
  let list: Array<childrenData> = [];

  provinceData.forEach((v) => {
    list.push({
      id: v.value ?? '',
      text: String(v.label),
      pid: v.pid,
      longitude: v.longitude,
      latitude: v.latitude,
      children: [],
    });
  });
  if (cityLevel == 'province') return list;
  cityData.forEach((item: any, index: number) => {
    item.forEach((citem: any, cindex: number) => {
      list[index].children.push({
        id: citem.value ?? '',
        text: citem.label ?? '',
        pid: citem.pid,
        longitude: citem.longitude,
        latitude: citem.latitude,
        children: [],
      });
    });
  });
  if (cityLevel == 'city') return list;
  list.forEach((item, index) => {
    item.children.forEach((citem, cindex: number) => {
      areaData[index][cindex].forEach((jitem: any) => {
        list[index]?.children[cindex]?.children.push({
          id: jitem.value ?? '',
          text: jitem.label ?? '',
          pid: jitem.pid,
          longitude: jitem.longitude,
          latitude: jitem.latitude,
          children: [],
        });
      });
    });
  });

  return list;
}